package com.syq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syq.mapper.DtsUserMapper;
import com.syq.pojo.DtsUser;
import com.syq.service.DtsUserService;
import com.syq.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @ClassName: DtsUserServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/22 16:00
 */
@Transactional
@Service
public class DtsUserServiceImpl implements DtsUserService {

    @Autowired
    private DtsUserMapper dtsUserMapper;

    @Override
    public Long findCount() {
        return dtsUserMapper.selectCount(null);
    }

    @Override
    public List<DayStatis> findUserOrderCntVo() {
        return dtsUserMapper.findUserOrderCntVo();
    }

    @Override
    public IPage<DtsUser> findByPage(Integer page, Integer limit, String username,String phone,String sort, String order) {
        return dtsUserMapper.selectPage(new Page<DtsUser>(page,limit),
                new QueryWrapper<DtsUser>()
                        .like(!StringUtils.isEmpty(username),"username",username)
                        .eq(!StringUtils.isEmpty(phone),"mobile",phone)
                        .orderBy(!StringUtils.isEmpty(sort),order.equalsIgnoreCase("Asc"),sort));
    }

    @Override
    public List<DayStatis> findUserCnt() {
        return dtsUserMapper.selectUserCnt();
    }
}
